From 8d3278f076b813d43c7918e20eeeb3ddaa5f3dd2 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Sat, 2 Mar 2002 21:01:20 +0000 Subject: [PATCH] Clamp @max parameter passed in to [0, MAX_SIZE], improve docs. Fix default Sat Mar 2 15:48:04 2002 Owen Taylor * gtk/gtkentry.c (gtk_entry_new_with_max_length, gtk_entry_set_max_length): Clamp @max parameter passed in to [0, MAX_SIZE], improve docs. Fix default and range for ::max-length property, range for ::ncursor_position, ::selection_bound properties. (#55916, Vitaly Tishkov) * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo --- ChangeLog | 10 ++++++++++ ChangeLog.pre-2-0 | 10 ++++++++++ ChangeLog.pre-2-10 | 10 ++++++++++ ChangeLog.pre-2-2 | 10 ++++++++++ ChangeLog.pre-2-4 | 10 ++++++++++ ChangeLog.pre-2-6 | 10 ++++++++++ ChangeLog.pre-2-8 | 10 ++++++++++ gtk/gtkentry.c | 44 ++++++++++++++++++++++++++++++++++++++------ gtk/gtkmain.c | 2 +- 9 files changed, 109 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 5fc8dfbc55..e1a60c606f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +Sat Mar 2 15:48:04 2002 Owen Taylor + + * gtk/gtkentry.c (gtk_entry_new_with_max_length, + gtk_entry_set_max_length): Clamp @max parameter passed in to + [0, MAX_SIZE], improve docs. Fix default and range + for ::max-length property, range for ::ncursor_position, + ::selection_bound properties. (#55916, Vitaly Tishkov) + + * gtk/gtkmain.c (rewrite_event_for_grabs): Fix typo + Fri Mar 1 18:39:44 2002 Owen Taylor * gdk/x11/{gdkevents-x11.c,gdkmain-x11.c,gdkprivate-x11.h, diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 830a9af171..7752125799 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -435,7 +435,7 @@ gtk_entry_class_init (GtkEntryClass *class) _("Cursor Position"), _("The current position of the insertion cursor in chars."), 0, - G_MAXINT, + MAX_SIZE, 0, G_PARAM_READABLE)); @@ -445,7 +445,7 @@ gtk_entry_class_init (GtkEntryClass *class) _("Selection Bound"), _("The position of the opposite end of the selection from the cursor in chars."), 0, - G_MAXINT, + MAX_SIZE, 0, G_PARAM_READABLE)); @@ -461,10 +461,10 @@ gtk_entry_class_init (GtkEntryClass *class) PROP_MAX_LENGTH, g_param_spec_int ("max_length", _("Maximum length"), - _("Maximum number of characters for this entry"), - -1, - G_MAXINT, - -1, + _("Maximum number of characters for this entry. Zero if no maximum."), + 0, + MAX_SIZE, + 0, G_PARAM_READABLE | G_PARAM_WRITABLE)); g_object_class_install_property (gobject_class, PROP_VISIBILITY, @@ -3257,11 +3257,30 @@ gtk_entry_new (void) return GTK_WIDGET (gtk_type_new (GTK_TYPE_ENTRY)); } +/** + * gtk_entry_new_with_max_length: + * @max: the maximum length of the entry, or 0 for no maximum. + * (other than the maximum length of entries.) The value passed in will + * be clamped to the range 0-65536. + * + * Creates a new #GtkEntry widget with the given maximum length. + * + * Note: the existance of this function is inconsistent + * with the rest of the GTK+ API. The normal setup would + * be to just require the user to make an extra call + * to gtk_entry_set_max_length() instead. It is not + * expected that this function will be removed, but + * it would be better practice not to use it. + * + * Return value: a new #GtkEntry. + **/ GtkWidget* gtk_entry_new_with_max_length (gint max) { GtkEntry *entry; + max = CLAMP (max, 0, MAX_SIZE); + entry = gtk_type_new (GTK_TYPE_ENTRY); entry->text_max_length = max; @@ -3417,12 +3436,25 @@ gtk_entry_select_region (GtkEntry *entry, gtk_editable_select_region (GTK_EDITABLE (entry), start, end); } +/** + * gtk_entry_set_max_length: + * @entry: a #GtkEntry. + * @max: the maximum length of the entry, or 0 for no maximum. + * (other than the maximum length of entries.) The value passed in will + * be clamped to the range 0-65536. + * + * Sets the maximum allowed length of the contents of the widget. If + * the current contents are longer than the given length, then they + * will be truncated to fit. + **/ void gtk_entry_set_max_length (GtkEntry *entry, gint max) { g_return_if_fail (GTK_IS_ENTRY (entry)); + max = CLAMP (max, 0, MAX_SIZE); + if (max > 0 && entry->text_length > max) gtk_editable_delete_text (GTK_EDITABLE (entry), max, -1); diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index c38607a39c..666f21254c 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -1056,7 +1056,7 @@ static GdkEvent * rewrite_event_for_grabs (GdkEvent *event) { GdkWindow *grab_window; - GtkWidget *event_widget, *grab_widget;; + GtkWidget *event_widget, *grab_widget; gboolean owner_events; switch (event->type) -- 2.30.2